﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for Exc_Room
/// </summary>
public class Exc_Room : NewDataAccess
{
	public Exc_Room()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public List<tbl_Room> SelectAllImgPartner(int partid)
    {
        List<tbl_Room> ImgList = new List<tbl_Room>();
        SqlDataReader R = GetData("select * from tbl_PartnerImg where PartnerID = " + partid + "  order by ImgPId desc ");
        try
        {
            while (R.Read())
            {
                tbl_Room C = new tbl_Room();
                C.ImgPId = R.GetInt32(0);
                C.PartnerID = R.GetInt32(1);
                C.ImgTitle = R.GetString(2);
                C.ImgDes = R.GetString(3);
                C.ImgUrl = R.GetString(4);
                C.Imgstatus = R.GetInt32(5);
                ImgList.Add(C);
            }
            return ImgList;
        }
        catch
        {
            R.Close();
            return null;
        }
    }

    public tbl_Room SelectImgPartner(int ImgId)
    {
        tbl_Room C = new tbl_Room();
        SqlDataReader R = GetData("select * from tbl_PartnerImg where ImgPId = " + ImgId);
        try
        {
            while (R.Read())
            {
                C.ImgPId = R.GetInt32(0);
                C.PartnerID = R.GetInt32(1);
                C.ImgTitle = R.GetString(2);
                C.ImgDes = R.GetString(3);
                C.ImgUrl = R.GetString(4);
                C.Imgstatus = R.GetInt32(5);
            }
            return C;
        }
        catch
        {
            R.Close();
            return null;
        }
    }

    public int AddImgPartner(int PartnerID, string ImgTitle, string ImgDes, string ImgUrl, int Imgstatus)
    {
        string cmd = "insert into tbl_PartnerImg(PartnerID, ImgTitle, ImgDes, ImgUrl, Imgstatus) values(" + PartnerID.ToString() + ",";
        cmd += "N'" + ImgTitle + "',";
        cmd += "N'" + ImgDes + "',";
        cmd += "N'" + ImgUrl + "',";
        cmd += Imgstatus.ToString() + ")";
        try
        {
            return ExcNonQuery(cmd);
        }
        catch
        {
            return 0;
        }
    }

    public int UpdateImgPartner(int ImgPId, int PartnerID, string ImgTitle, string ImgDes, string ImgUrl, int Imgstatus)
    {
        string cmd = "update tbl_PartnerImg set PartnerID = " + PartnerID.ToString() + ",";
        cmd += "ImgTitle = N'" + ImgTitle + "',";
        cmd += "ImgDes = N'" + ImgDes + "',";
        cmd += "ImgUrl = N'" + ImgUrl + "',";
        cmd += "Imgstatus =  " + Imgstatus.ToString() + " where ImgPId = " + ImgPId.ToString();
        try
        {
            return ExcNonQuery(cmd);
        }
        catch
        {
            return 0;
        }
    }

    public int DeleteImgPartner(int ImgPId)
    {
        string cmd = "delete from tbl_PartnerImg where ImgPId = " + ImgPId;
        try
        {
            return ExcNonQuery(cmd);
        }
        catch
        {
            return 0;
        }
    }

    public int DeleteAllImgPartner(int PartnerID)
    {
        string cmd = "delete from tbl_PartnerImg where PartnerID = " + PartnerID;
        try
        {
            return ExcNonQuery(cmd);
        }
        catch
        {
            return 0;
        }
    }
}